export const FormatModel = function (Model) {
    const ViewModel = [];
    const ParamsModel = {};
    for (let i = 0; i < Model.Param.length; i++) {
        const element = Model.Param[i];
        ParamsModel[element.Key] = JSON.parse(JSON.stringify(element));
    }

    for (let i = 0; i < Model.View.length; i++) {
        const element = Model.View[i];
        const ViewItem = {
            title: element.title,
            children: [],
        }
        for (let d = 0; d < element.children.length; d++) {
            const child = element.children[d];
            ParamsModel[child] && ViewItem.children.push(ParamsModel[child]);
        }
        ViewModel.push(ViewItem);
    };
    return ViewModel;
}

export const FormModel2Object = function (Model) {
    const _obj = {};

    for (let i = 0; i < Model.Param.length; i++) {
        const element = Model.Param[i];
        if (element.hasOwnProperty('Default')) {
            _obj[element.Key] = element.Default
        } else {
            switch (element.FormType) {
                case 'String':
                    _obj[element.Key] = '';
                    break;
                case 'Number':
                    _obj[element.Key] = 0;
                    break;
                default:
                    _obj[element.Key] = null;
                    break;
            }
        }
    }
    return _obj;
}
